package cn.job.j2
import scala.collection.mutable.Map

class Game {

  // 甲方玩家
  var guest: Map[String, Int] = Map("胜" -> 0, "和" -> 0, "负" -> 0)

  // 乙方玩家
  var computer: Map[String, Int] = Map("胜" -> 0, "和" -> 0, "负" -> 0)

  // 对战次数
  var vsCount: Int = 0

  /**
   * 角色信息
   */
  val role: Map[Int, String] = Map(1 -> "刘备", 2 -> "关羽", 3 -> "张飞")

  /**
   * 拳头定义
   */
  val fist: Map[Int, String] = Map(1 -> "剪刀", 2 -> "石头", 3 -> "布")

  def getMapString(map: Map[Int, String]): String = {
    var s = ""
    map.foreach((k) => {
      s += s"${k._1}.${k._2} "
    })
    s
  }

  def getRole: String = {
    getMapString(role)
  }

  def getFist: String = {
    getMapString(fist)
  }

  /**
   * val fist: Map[Int, String] = Map(1 -> "剪刀", 2 -> "石头", 3 -> "布")
   * 1 平局了
   * 2 胜利了
   * 0 失败了
   *
   * @param fist1 用户1
   * @param fist2 用户2
   * @return
   */
  def diff(fist1: Int, fist2: Int): Int = {
    if (fist1 == fist2) {
      return 1
    }
    if (fist1 == 1 && fist2 == 3) {
      return 2
    }
    if (fist1 == 3 && fist2 == 1){
      return 0
    }
    if (fist1 > fist2) {
      return 2
    }
    0
  }
}
